package com.wkx.controller;/**
 * @className: MainController
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/8
 **/

import com.wkx.pojo.Admin;
import com.wkx.pojo.Menu;
import com.wkx.pojo.Roles;
import com.wkx.service.MenuService;
import com.wkx.service.RoleService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : MainController  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/8  12:04
 */
@Controller
@RequestMapping("main")
public class MainController {
    private Logger logger = LoggerFactory.getLogger(AdminController.class);
    @Reference(url = "dubbo://localhost:20881")
    private RoleService roleService;
    @Reference(url = "dubbo://localhost:20881")
    private MenuService menuService;

    @RequestMapping("toMain")
    public String toMain(HttpSession session, Model model){
        logger.info("主页面");
        Map<Integer,Object> map = new HashMap<>();
        Admin user = (Admin) session.getAttribute("user");
        List<Roles> rolesList = roleService.getRolesListByAid(user.getaId());
        List<Menu> fMenuList = menuService.getMenuList(0, rolesList);
        map.put(0,fMenuList);
        for (Menu menu : fMenuList) {
            List<Menu> sMenuList = menuService.getMenuList(menu.getId(), rolesList);
            map.put(menu.getId(),sMenuList);
        }
        /*session.setAttribute("map",map);*/
        model.addAttribute("map",map);
        return "main_two";
    }
}
